<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <script type="text/javascript">
      Ext.onReady(function(){
        var id = <%=params[:id]%>       //从前面的链接得到id的值

        var checkInTime = new Ext.ux.form.DateTimeField({
          fieldLabel: '打卡开工时间',
          width: 200,
          name: 'check_in_time',
          id: 'check_in_time',
          format: 'Y-m-d', //格式化日期
          invalidText: "您输入的日期格式不对，格式应如：2010-01-01",
          allowBlank: false,
          blankText: "维护单元规定开工时间必须选择",
          emptyText: '请选择时间...'
        });

        var editMaintenanceForm=new Ext.form.FormPanel({
          width:230,
          url:'/maintenance/addCheckIn',
          labelAlign: 'top',
          buttonAlign:'center',
          bodyStyle: 'padding:5px',
          labelWidth:100,
          frame: true,
          reader:new Ext.data.JsonReader({
          },[
            {name:'check_in_time'}
          ]),
          items:[
            {
              xtype: 'hidden',
              name:  'id',
              value: id
            },
            {layout:'column',labelAlign: 'top',                            //栏目，占据一整行
              items:[{columnWidth:1,layout:'form'
                  ,items:[checkInTime]
                }]}
          ],
          buttons:[{
              text:'确认保存',
              handler: function(){
                if (editMaintenanceForm.form.isValid()) {
                  editMaintenanceForm.form.submit({
                    method: 'post',
                    success: function(result, response){
                      if (response.result.info == "success") {
                        //添加成功后，隐藏窗口，并刷新Grid
                        checkInWin.destroy();
                      }
                      else {
                        Ext.MessageBox.alert('消息', response.result.info);
                      }
                    },
                    failure: function(result, response){
                      Ext.MessageBox.alert('提示', result.responseText);
                    }
                  });
                }
                else {
                  Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
              }
            },{
              text:'取消',
              handler:function(){
                checkInWin.destroy();
              }
            }]
        });
        editMaintenanceForm.render('checkInForm');
      });
    </script>
  </head>
  <body>
    <div id="checkInForm"></div>
  </body>
</html>